page = {
	cur:1,
	num:7,
	painationClass:'pagination',
	dynamicClass:'dynamic',
	navClass:'paginationNav',
	prevLabel:'上一页',
	prevClass:'prev',
	nextClass:'next',
	nextLabel:'下一页',
	currentPageClass:'currentPage',
	num:10,
	init:function(){
		var tables,table,tablebody,trs,i,caption;
		tables = tn('table');
		for(i=0;i<tables.length;i += 1){
			table = tables[i]
			tablebody = tn('tbody',table)[0];
			caption = tn('caption',table)[0].style.display='none';
			table.trs = tn('tr',tablebody);
			page.intervalColumn(table.trs);
			//if(!DOMhelp.cssjs('check',table,page.painationClass)){
			//	continue;
			//}
			if(tn('tr',table).length<page.num+2){
				continue;
			}
			table.trsize = table.trs.length;
			table.current = null;
			page.createNav(table);
			page.showTr(table,0);
			DOMhelp.cssjs('add',table,page.dynamicClass);
		}
	},
	createNav:function(table){
		var i,pageNode,
		    numAs = [],
		    length = Math.ceil(table.trsize/page.num),
			prev = ce('a',{'href':'#','class':page.prevClass},page.prevLabel),
			next = ce('a',{'href':'#','class':page.nextClass},page.nextLabel),
		    a = ce('a',{'class':'pageNum'}),
			p = ce('p',{'class':page.navClass,'id':'navLink'});
		DOMhelp.addEvent(prev,'click',page.nav,false);
		DOMhelp.addEvent(next,'click',page.nav,false);
		p.appendChild(prev);
		for(i=0;i<length;i += 1){
			pageNode = a.cloneNode(false);
			pageNode.innerHTML = i + 1;
			pageNode.setAttribute('href','#');
			pageNode.cur = i*page.num;
			pageNode.start = i*page.num + 1;
			DOMhelp.addEvent(pageNode,'click',page.nav,false);
			p.appendChild(pageNode);
			numAs[numAs.length] = pageNode;
		}
		p.appendChild(next);
		table.parentNode.insertBefore(p,table.nextSibling);
		table.prev = prev;
		table.next = next;
		table.nav = p;
		table.numAs = numAs;
	},
	nav:function(e){
		var start,table,b,
		    a = DOMhelp.getTarget(e);
		while(a.nodeName.toLowerCase() != 'a'){
			a = a.parentNode;
		}
		if(a.getAttribute('href')===null || a.getAttribute('href')===''){return;}
		table = a.parentNode.previousSibling;
		if(a===table.prev){
			start = table.current-page.num;
		} else if(a===table.next){
			start = table.current+page.num;
		} else if(a.cur !== undefined){
			start = a.cur;
		}
		page.showTr(table,start);
		DOMhelp.cancelClick(e);
	},
	changeNav:function(table,start){
		var i;
		if(start-page.num<0){
			table.nav.removeChild(table.prev);
		}else{
			table.nav.insertBefore(table.prev,fc(table.nav));
		}
		if(start+page.num>table.trsize-1){
			table.nav.removeChild(table.next);
		}else{
			table.nav.appendChild(table.next);
		}
	},
	showTr:function(table,start){
		var i,tr,a;
		page.changeNav(table,start);
		if(table.current!==null){
			for(i=table.current;i<table.current+page.num;i++){
				tr = table.trs[i];
				if(tr){
					DOMhelp.cssjs('remove',tr,'show');
				}
			}
		}
		for(i=start;i<start+page.num;i+=1){
			tr = table.trs[i]
			if(tr){
				DOMhelp.cssjs('add',tr,'show');
			}
		}
		if(table.current !== null){
			b = table.numAs[table.current/page.num];
			DOMhelp.cssjs('remove',b,page.currentPageClass);
			b.setAttribute('href','#');
		}
		a = table.numAs[start/page.num];
		DOMhelp.cssjs('add',a,page.currentPageClass);
		a.removeAttribute('href');
		table.current = start;
	},
	intervalColumn:function(trs){
		var i,tr;
		for(i=0;i<trs.length;i+=1){
			tr = trs[i];
			if(i%2===1){
				DOMhelp.cssjs('add',tr,'odd');
			}else{
				DOMhelp.cssjs('add',tr,'even');
			}
		}
	}
}
DOMhelp.addEvent(window,'load',page.init);